package com.imay.live.fragment.room;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.imay.base.fragment.BaseDialogFragment;
import com.imay.live.R;
import com.imay.live.helper.DialogFragmentHelper;
import com.imay.live.utils.GlideUtil;
import com.imay.live.utils.ViewUtil;
import com.imay.live.view.dialog.ShareDialogFragment;
import com.imay.tsnackbar.TSnackbar;

/**
 * Created by Administrator on 2017/7/28 0028.
 */

public class ScreenshotFragment extends BaseDialogFragment implements View.OnClickListener {

    public final static String SCREENSHOTPATH = "screenshotpath";

    private String path;

    private ImageView mScreenshot;
    private TextView mButton;

    public static ScreenshotFragment newInstance(String path) {
        Bundle args = new Bundle();
        args.putString(SCREENSHOTPATH, path);
        ScreenshotFragment fragment = new ScreenshotFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected boolean isMatchParent() {
        return false;
    }

    @Override
    protected int getHeight() {
        return WindowManager.LayoutParams.WRAP_CONTENT;
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_screenshot;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        mScreenshot = $(R.id.iv_screenshot);
        $(R.id.iv_cancel).setOnClickListener(this);
        $(R.id.bt_share_screenshot).setOnClickListener(this);

        path = getArguments().getString(SCREENSHOTPATH);

        GlideUtil.loadRectangleImage(mScreenshot, path, R.dimen.size_4dp, R.drawable.shape_placeholder_2);

        float r = getResources().getDimension(R.dimen.radius_4x);

        ViewUtil.setRadius(mScreenshot, r, Color.TRANSPARENT);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        TSnackbar.make(getActivity().getWindow().getDecorView(), getString(R.string.sceenshot_save_success)).show();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_cancel:
                dismissAllowingStateLoss();
                break;
            case R.id.bt_share_screenshot:
                synchronized (v) {
                    DialogFragmentHelper.showDialogFragment(getChildFragmentManager(), ShareDialogFragment.newInstance(ShareDialogFragment.IMG_FILE, null, null, null, path));
                }
                break;
        }
    }
}
